package cn.ckx.coding.moudle.user.controller;

import cn.ckx.coding.common.validation.group.GroupCreate;
import cn.ckx.coding.moudle.user.dto.UserDTO;
import cn.ckx.coding.moudle.user.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;

/**
 * @ClassName UserController
 * @Description
 * @Author kunxin.cai
 * @Date 2021/2/26
 * @Version 1.0
 **/
@Api(tags = "用户")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@RequestMapping("/user")
@RestController
public class UserController {
    
    private final UserService userService;
    
    @ApiOperation("登录-账号密码")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "accNumber",value = "账号",required = true),
            @ApiImplicitParam(name = "accNumber",value = "密码",required = true),
    })
    @PostMapping("login/accNumber")
    public UserDTO login(@NotBlank(message = "账号不能为空") String accNumber,
                         @NotBlank(message = "密码不能为空") String password) {
        return userService.loginByAccNum(accNumber,password);
    }


    @ApiOperation("注册-账号密码-无实现其他处理")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "accNumber",value = "账号",required = true),
            @ApiImplicitParam(name = "accNumber",value = "密码",required = true),
    })
    @PostMapping("register")
    public UserDTO register(@Validated(GroupCreate.class) UserDTO user) {
        return userService.register(user);
    }   
    
}
